package com.ruoyi.business.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.business.service.DefaultLoginService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Tellsea
 * @date 2024/2/28
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class DefaultLoginServiceImpl implements DefaultLoginService {

    private final SysLoginService loginService;
    private final ISysUserService sysUserService;

    @Override
    public AjaxResult login(LoginBody entity) {
//        SysUser sysUser = sysUserService.lambdaQuery().eq(SysUser::getIdCard, entity.getIdCard()).one();
//        if (ObjectUtil.isEmpty(sysUser)) {
//            return AjaxResult.error("身份证号未找到");
//        }
//        if (!StrUtil.equals(sysUser.getUserName(), entity.getUsername())) {
//            return AjaxResult.error("身份证号和账号不匹配");
//        }
        String token = loginService.login(entity.getUsername(), entity.getPassword());
        return AjaxResult.success("登录成功", token);
    }
}
